package cn.tedu.micro.demo.device.service.impl;

import cn.tedu.micro.demo.common.vo.GunInfoVO;
import cn.tedu.micro.demo.device.dao.mapper.GunInfoMapper;
import cn.tedu.micro.demo.device.dao.repository.DeviceRepository;
import cn.tedu.micro.demo.device.po.GunInfoPO;
import cn.tedu.micro.demo.device.service.DeviceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class DeviceServiceImpl implements DeviceService {
    @Autowired
    private DeviceRepository deviceRepository;
    /**
     * 基于业务流程图 开发业务代码
     * @param gunId
     * @return
     */
    @Override
    public GunInfoVO getGunInfo(Integer gunId) {
        //1.读取一个持久层po对象
        GunInfoPO po=deviceRepository.getGunInfoById(gunId);
        //判断: po空 或者 不空 处理逻辑不同
        GunInfoVO vo=null;
        if (po!=null){
            //2.非空 vo初始化 转化封装po3个属性 id status type
            vo=new GunInfoVO(po.getId(),po.getStatus(),po.getType());
        }
        return vo;
    }
    /*//TODO 尽可能避免业务和数据实现的耦合
    private GunInfoPO getGunInfoById(Integer gunId) {
        return gunInfoMapper.selectById(gunId);
    }*/

}
